package com.um2.mauction.java;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.um2.mauction.session.impl.UserManagerBean;
import com.um2.mauction.session.remote.UserManagerRemote;

public class FrmProfilValiderModificationAction extends Action 
{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws IOException, ServletException 
	{
		//String resultat = null;
		FrmInscriptionVisitorBean formulaire = (FrmInscriptionVisitorBean) form;

		String login = formulaire.getTxtLogin();
		String motDePasse = formulaire.getTxtMdp();
		String nom = formulaire.getTxtNom();
		String prenom = formulaire.getTxtPrenom();
		String adresse = formulaire.getTxtAddress();
		String email = formulaire.getTxtEmail();

		//On remplit les champs du formulaires avec les valeurs d�ja dessu
		request.setAttribute("txtLogin", login);
		request.setAttribute("txtMdp", motDePasse);
		request.setAttribute("txtNom", nom);
		request.setAttribute("txtPrenom", prenom);
		request.setAttribute("txtAddress", adresse);
		request.setAttribute("txtEmail", email);

		UserManagerRemote user_manager = null;
		try 
		{
			InitialContext ic = new InitialContext();
			user_manager = (UserManagerRemote) ic
			.lookup(UserManagerBean.RemoteJNDIName);
			System.out.println("MANAGER:" + user_manager);
			user_manager.addUtilisateur(login, motDePasse, nom, prenom, adresse, email);

			//resultat = "success";
		} 
		catch (Exception ex) 
		{
			System.out.println("ERREUR!!" + ex.getMessage());
			//resultat = "failure";
		}
		return mapping.findForward("reponse");
	}
}